package com.project_doctor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project_doctor.code.SystemCode;
import com.project_doctor.pojo.Service;
import com.project_doctor.pojo.common.MyPageData;
import com.project_doctor.pojo.dto.ServiceDTO;
import com.project_doctor.service.ServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/service")
public class ServiceController {
    @Autowired
    private ServiceService serviceService;

    //获取服务项目分页
    @PostMapping("/serviceList/{pageNum}/{pageSize}")
    public ResponseEntity<?> getContractVoList(@RequestBody ServiceDTO queryDTO,
                                               @PathVariable Integer pageNum,
                                               @PathVariable Integer pageSize) {
        // 设置需要排除的状态值
        Page<Service> page = serviceService.getServiceList(queryDTO,pageNum,pageSize);
        List<Service> services = page.getRecords();

        MyPageData data = new MyPageData(page.getTotal(),services);

        return ResponseEntity.ok(data);
    }
    //删除服务项目数据
    @DeleteMapping("/deleteService/{id}")
    public ResponseEntity<?> deleteService(@PathVariable Integer id) {
        serviceService.deleteService(id);
        return ResponseEntity.ok(SystemCode.DELETE_SUCCESS.getMessage());
    }
    //修改服务项目数据
    @PutMapping("/getServiceById/{id}")
    public ResponseEntity<?> getServiceById(@PathVariable Integer id) {
        Service service = serviceService.getServiceById(id);
        return ResponseEntity.ok(service);
    }
    //新增服务项目数据
    @PostMapping("/addOrUpdateService")
    public ResponseEntity<?> addOrUpdateService(@RequestBody Service service) {
        serviceService.saveOrUpdate(service);
        return ResponseEntity.ok(SystemCode.SUCCESS.getMessage());
    }
}
